<%@tag pageEncoding="UTF-8" import="java.util.Map"%>
<%@taglib prefix="commonUI" tagdir="/WEB-INF/tags/common/UI"%>
<%@attribute name="bean" type="ajaxjs.service.Service_Restful" required="true" description="依赖注入一个 bean，用来获取分类"%> 
<style type="text/css">
	dl{
		width:50%;
		margin:10px;
	}
	dt,dd{
		display:inline-block;
	}
	dt {
		width:15%;
		vertical-align: top;
	}
	dd{
		width:28%;
	}
</style>
<form action="../../service/${param.belongsto}/catalog/${param.id}">
<%
	if(request.getParameter("id") == null){
		out.write("没有id！");
		return;
	}
	Map<String, Object> catalogInfo = bean.getInfo("/news/catalog/", request.getParameter("id"));
	request.setAttribute("catalogInfo", catalogInfo);
	
	System.out.println(catalogInfo);
%>
	<dl>
		<dt>#：</dt>
		<dd>${param.id}</dd>
		<dt>Belongs to:</dt>
		<dd>${param.belongsto}</dd>
	</dl>
	<dl>
		<dt>ID：</dt>
		<dd><%=catalogInfo.get("key")%></dd>
		<dt>名称：</dt>
		<dd><input type="text" name="name" value="<%=catalogInfo.get("name")%>" /></dd>
	</dl>
	<dl>
		<dt>简介：</dt>
		<dd style="width:80%;">
			<commonUI:htmlEditor iframePath="../public/" basePath="" name="content" isSimple="true" openUploaderByGallery="true">
				${catalogInfo.value}
			</commonUI:htmlEditor>
			
			<textarea rows="" cols="" class="hide textContent">${catalogInfo.content}</textarea>
			<script>
		    	seajs.use(['bigfoot/dhtml/form/form', 'bigfoot/widget/htmlEditor'], 
		    		function(_form, _htmlEditor){
		    		// 表单提交
		    		var formEl = document.querySelector('form'),
		    		form = Object.create(_form);
		    		form.formEl = formEl;
		    		form.PUT = true;
		    		form.init();
		    		
		    		bf.htmlEditor = _htmlEditor; // 单例
		    		_htmlEditor.el = document.querySelector('.htmlEditor');
		    		_htmlEditor.init();
		    		_htmlEditor.setValue(document.querySelector('.textContent').value); 
		    	});
		    	
	    		seajs.use('bigfoot/widget/upload/panel', function(_upload){
	    			
					// 封面图    			
	    			document.body.$click('.uploadCover', function(){
			    		// 图片 belongsto 大类，不设分类了
			    		
			    		// 获取文件夹路径
						var belongsto = location.search.match(/belongsto=([^&]*)/).pop();
						var id = location.search.match(/id=(\d+)/).pop();
			    		var uploadDialog = Object.create(_upload);
	    				uploadDialog.serviceUrl	= serviceUrl + 'catalog/' + id + '/img';
	    				uploadDialog.delUrl		= serviceUrl + 'img';
	    				uploadDialog.createUrl	= serviceUrl + 'catalog/img?parentId=' + id;
	    				uploadDialog.setCoverUrl= serviceUrl + '/' + id;
	    				uploadDialog.urlPrefix	= '../../public/gallery';
						
						uploadDialog.init(document.querySelector('.setCover'));
						uploadDialog.loadImgs(serviceUrl + 'catalog/' + id + '/img');
	    			});
	    		});
	    	</script>
		</dd>
	</dl>
	<dl>
		<dt>所在频道：</dt>
		<dd style="width:50%;">
			<label>
			<input type="radio" name="channel" value="1" <%=catalogInfo.get("channel").toString().equals("1") ? "checked" : ""%> /> 湛江台综合频道 
			</label>
			<label>
			<input type="radio" name="channel" value="2" <%=catalogInfo.get("channel").toString().equals("2") ? "checked" : ""%> /> 湛江台公共频道
			</label>
		</dd>
	</dl>
	<dl>
		<dt>封面图：</dt>
		<dd>
			<a href="#" class="uploadCover">上传封面图</a>
		</dd>
	</dl>
	
	<div class="btns">
		<button>保存</button>
		<button class="return">返回</button>
	</div>
</form>